home *** CD-ROM | disk | FTP | other *** search
- ;
- ; CBLibrary
- ; Copyright (C) 2003 Chris Bazley
- ;
- ; This library is free software; you can redistribute it and/or
- ; modify it under the terms of the GNU Lesser General Public
- ; License as published by the Free Software Foundation; either
- ; version 2.1 of the License, or (at your option) any later version.
- ;
- ; This library is distributed in the hope that it will be useful,
- ; but WITHOUT ANY WARRANTY; without even the implied warranty of
- ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- ; Lesser General Public License for more details.
- ;
- ; You should have received a copy of the GNU Lesser General Public
- ; License along with this library; if not, write to the Free Software
- ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- ;
-
- ; Support code for psuedo pre-emptive multitasking
- ; 11.09.03 CJB Added BOOL_8_BIT variable to control width of type 'bool'.
-
- EXPORT timer_register
- EXPORT timer_deregister
-
- AREA |C$$code|, CODE, READONLY
-
- Auto_Error_SWI_bit_number * 17
- Auto_Error_SWI_bit * 1 :SHL: Auto_Error_SWI_bit_number
-
- XOS_CallAfter * &3B + Auto_Error_SWI_bit
- XOS_RemoveTickerEvent * &3D + Auto_Error_SWI_bit
-
- GBLL BOOL_8_BIT
- BOOL_8_BIT SETL {TRUE}
- ; This controls whether the type 'bool' is 8 or 32 bits wide.
- ; The stdbool header supplied with recent versions of Castle's C compiler (5.50 and later?) defines 'bool' as the built-in 8 bit type '_Bool'.
- ; However the stdbool header supplied with earlier compiler releases instead defined 'bool' as 'int' (32 bits wide).
-
- timer_set_flag
- ; Called in SVC mode with interrupts disabled
- ; Must preserve all registers and return using MOV PC,R14
- ; R12 = pointer to timeup flag
-
- STR R14,[R13,#-4]! ; push return address
-
- MOV R14,#1
- [ BOOL_8_BIT
- STRB R14,[R12] ; set flag byte
- |
- STR R14,[R12] ; set flag word
- ]
-
- LDR PC,[R13],#4 ; pull return address
-
-
- ; _kernel_oserror *timer_register(volatile bool *timeup_flag, unsigned int wait_time)
- timer_register
- ; a1 = pointer to bool
- ; a2 = delay in cs
- MOV ip,lr
-
- MOV lr,#0
- [ BOOL_8_BIT
- STRB lr,[a1] ; clear flag byte
- |
- STR lr,[a1] ; clear flag word
- ]
-
- MOV a3,a1 ; R12 value for routine is pointer to flag
- MOV a1,a2 ; delay in cs
- ADR a2,timer_set_flag ; pointer to routine
- SWI XOS_CallAfter
- MOVVC a1,#0 ; if no error then return NULL
-
- [ {CONFIG} = 26
- MOVS pc,ip ; APCS-R
- |
- MOV pc,ip ; APCS-32
- ]
-
-
- ; _kernel_oserror *timer_deregister(volatile bool *timeup_flag)
- timer_deregister
- ; a1 = pointer to bool
- MOV ip,lr
- MOV a2,a1 ; R12 value for routine is pointer to flag
- ADR a1,timer_set_flag ; pointer to routine
- SWI XOS_RemoveTickerEvent
- MOVVC a1,#0 ; if no error then return NULL
-
- [ {CONFIG} = 26
- MOVS pc,ip ; APCS-R
- |
- MOV pc,ip ; APCS-32
- ]
-
- END
-